<template name="newpintuanbottom">
	<view class="goodBtm">
		<text class="stockNull" v-if="resouceData.stock<1">该活动已结束</text>
		<view class="goodOp">
			
			<!-- <view class="item" @tap="zixun">
				<text class="iconfont icon-message"></text>
				<text>咨询</text>
			</view> -->
			<view class="item" @tap="share" >
				<text class="iconfont icon-fenxiang1"></text>
				<text>分享</text>
			</view>
			
			<view class="item" @tap="toPage" :data-id="resouceData.cStoreId" data-url="shopDetail">
				<text class="iconfont icon-shoucangdianjia"></text>
				<text>店铺</text>
			</view>
			
			<!-- <view class="item" @tap="guanzhu">
				<text class="iconfont" :class="[goodData.fav==1?'icon-likefill':'icon-like']"></text>
				<text>{{goodData.fav==1?'已关注':'关注'}}</text>
			</view> -->
			
			<view class="btnBox">
				<button @tap="buyyuanjia">
				    <text>￥{{resouceData.course.price}}</text>
					<text>单独购买</text>
				</button>
				<button  @tap="buy">
					<text>￥{{resouceData.spellPrice}}</text>
					<text>立即开团</text>
				</button>									
			</view>
		</view>
		
		<!-- 登录的新组件 -->
		<uni-popup ref="popup" type="center" mask-click="false" @touchmove.stop.prevent="moveHandle">
			<newlogin @tap="close"></newlogin>
		</uni-popup>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters,
		mapMutation,
		mapActions
	} from "vuex";
	export default {
		computed: {
			...mapState({
				userInfo: state => state.user.userInfo,
				isLogin: state => state.user.isLogin
			})
		},
		name: 'newpintuanbottom', //组件名称
		// 传递参数
		props: {
			resouceData: {
				type: Object,
				default: ()=>{
					return {
						leftSeconds:1
					}
				}
			}
		},
		// 组件参数
		data() {
			return {
				shopInfo: {
					id:0
				},
				goodData:{},
			}
		},
		watch:{
			resouceData(newVal){
				this.mtd1();
			}
		},
		// 组件方法
		methods: {
			share() {
				this.$parent.showPoster();
			},
			
			open() {
				// 通过组件定义的ref调用uni-popup方法
				this.$refs.popup.open();
				
			},
			close() {
				// 通过组件定义的ref调用uni-popup方法
				this.$refs.popup.close();
				
			},
			moveHandle(){
				return;
			},
			mtd1() {
				this.goodData=this.resouceData.course;
				this.shopInfo=this.resouceData.course.store;
				
			},
			zixun() {
				let _this = this;
				if (this.isLogin) {
					uni.showLoading({
						title: '',
						mask: false
					});					
					let toImid = _this.shopInfo.imid;
					if (getApp().globalData.TIM_SDK_READY) {
						uni.hideLoading()
						_this.toPage({
							url: 'conversationDt',
							cvid: 'C2C' + toImid,
							toImId: toImid
						})
					} else {
						_this.$store.dispatch("timLogin",_this.userInfo.imid).then(res=>{
							setTimeout(() => {
								uni.hideLoading()
								_this.toPage({
									url: 'conversationDt',
									cvid: 'C2C' + toImid,
									toImId: toImid,
								})
							}, 1000)
						})
					}
				} else {
					// this.toPage({
					// 	url:'login'
					// })	
						this.open();
				}
			},
			buyyuanjia() {
				if (this.isLogin) {
					let cfmArr = [this.goodData];
					
					uni.setStorage({
						key: 'confirmList',
						data: cfmArr,
						complete: () => {
							this.toPage({
								url: 'confirmOrder',
								newdandu:1
							})
						}
					})
			
				} else {
					// this.toPage({
					// 	url:'login'
					// })	
					this.open();
				}
			},
			buy() {
				
				
				
				let _now = new Date();
				var _kaishi = new Date(this.resouceData.startTime.replace(/-/g, '/'));
				var _end = new Date(this.resouceData.endTime.replace(/-/g, '/'));
				var _zhanshiTime = _kaishi.getTime() - _now.getTime();
				var _endTime = _end.getTime() - _now.getTime();
				
				if (_zhanshiTime > 0) {
					uni.showModal({
						content: '活动即将开始!',
						success: function(res) {
							if (res.confirm) {
							} else if (res.cancel) {
							}
						}
					});
				} else if (_endTime <= 0) {
					uni.showModal({
						title: '友情提示',
						content: '该活动已结束！',
						success: function(res) {
							if (res.confirm) {
							} else if (res.cancel) {
							}
						}
					});
				}else if (this.isLogin) {
					
					
					this.$set(this.goodData,'spellPrice',this.resouceData.spellPrice)
					// let cfmArr = [this.goodData.spellPrice = this.resouceData.spellPrice];
					let cfmArr = [this.goodData];
					uni.setStorage({
						key: 'confirmList',
						data: cfmArr,
						complete: () => {
							this.toPage({
								url: 'confirmOrder',
								newisGroup:1,
								newpt:this.resouceData.id								
							})
						}
					})
					
				} else {
					// this.toPage({
					// 	url:'login'
					// })		
					this.open();
				}
				
			},
			
		
		},
		onShow() {
			this.mtd1()
		},
	
		created() {
			setTimeout(()=>{
				this.mtd1()
			},500)
			
		}
	}
</script>

<style lang="less" scoped>
	.goodBtm {
		position: fixed;
		width: 100%;
		height: 180upx;
		bottom: 0;
		left: 0;
		display: flex;
		flex-direction: column;
		justify-content: flex-end;
		z-index: 2;

		.priceBox {
			height: 75upx;
			display: flex;
			align-items: center;
			background-color: #f8e4a9;
			padding: 0 50upx;

			.iconfont {
				font-size: 40upx;
				color: #ff3b2b;
				margin-right: 16upx;
			}

			text {
				font-size: 32upx;
				color: #a17f68;
			}

			.yyPrice {
				color: #ff3b2b;
				font-size: 38upx;
				flex: 1;
			}

			.zaifu {
				color: #a17f68;
				font-size: 38upx;
			}
		}

		.stockNull {
			background-color: #333333;
			color: #FFFFFF;
			line-height: 75upx;
			text-align: center;
			font-size: 28upx;
		}

		.goodOp {
			box-sizing: border-box;
			height: 105upx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			background-color: #FFFFFF;
			padding: 0 0 0 38upx;
			border-top: 1px solid #b5bac2;

			.item {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				text {
					color: #6b6b6b;
					font-size: 20upx;
				}

				.iconfont {
					font-size: 48upx;
					color: #2c2c2c;
				}
			}

			.btnBox {
				display: flex;
				align-items: center;
				height: 105upx;
				position: relative;
				// border-radius: 52rpx;
				// overflow: hidden;
				
				button {
					width: 250upx;
					border: none;
					margin: 0;
					outline: none;
					height: 80upx;
					line-height: 105upx;
					font-size: 32upx;
					color: #FFFFFF;
					font-weight: bold;
					border-radius: 0upx;
					background: linear-gradient(to right, #ffc300, #ff9503);
				}

				button:after {
					border: none;
					outline: none;
				}

				button:first-child {
					display: flex;
					flex-direction: column;
					line-height: 1;
					justify-content: center;
					border-bottom-left-radius: 40rpx;
					border-top-left-radius: 40rpx;

					text:last-child {
						font-weight: normal;
						font-size: 24upx;
						margin-top: 4upx;
						
					}
				}

				button:last-child {
					background: linear-gradient(to right, #fe5828, #fe305b);
					display: flex;
					flex-direction: column;
					line-height: 1;
					justify-content: center;
					border-bottom-right-radius: 40rpx;
					border-top-right-radius: 40rpx;
					

				}

				button[disabled=true] {
					color: #EEEEEE;
				}
				a{
					text-decoration: none;
					position: absolute;
					display: block;
					width: 100%;
					height: 100%;
					z-index: 555;
					top: 0;
					left: 0;
				}
			}
		}
	}
</style>
